** file to analyse FOI replication study for JBPA **

clear 

import excel "/Users/peterjohn/Dropbox/Documents/experiments/FOI-replication/data/datasetFOIexperiment 3 april 2018.xlsx", sheet("datasetFOIexperiment 3 april 20") firstrow


** balance checks **

recode Response 999=.
recode pretreated .=0 2=1 1=0 999=.

ttest income, by(Group)
ttest Residents, by(Group)
ttest FOIpres, by(Group)
ttest previousrequests, by(Group)
ttest meetingminutes, by (Group)

reg Group Residents FOIpres previousrequests meetingminutes

** core table **

tab Response Group, col
tab Response Group if pretreated==1, col

** 2*2 table **

gen Response01=Response
recode Response01 .=. 0=0 else=1

tab Response01 Group, col chi
tab Response01 Group if pretreated==1, col chi

** anova

oneway Response Group

** partial compliance

gen partial=Response
recode partial 0=0 1=1 2=1 3=1 4=0

tab partial Group, col chi

** full compliance

gen full=Response
recode full 0=0 1=0 2=0 3=0 4=1
tab full Group, col chi

** subset on who published **

tab Response Group if pretreated ==1, col
tab Response01 Group if pretreated ==1, col


** regression

oprobit Response Group
estimates store A
oprobit Response Group income Residents FOIpres previousrequests meetingminutes pretreated
estimates store B


** exploring with probit

gen response01000=Response
recode response01000 0=0 1=1 2=0 3=0 4=0

gen response00100=Response
recode response00100 0=0 1=0 2=1 3=0 4=0

gen response00010=Response
recode response00010 0=0 1=0 2=0 3=1 4=0

gen response00001=Response
recode response00001 0=0 1=0 2=0 3=0 4=1


** interactions ** 

gen ResidentsGroup=Residents*Group
oprobit Response Group income Residents FOIpres previousrequests meetingminutes pretreated ResidentsGroup
estimates store C
gen pretreatedGroup=pretreated*Group
oprobit Response Group income Residents FOIpres previousrequests meetingminutes pretreated pretreatedGroup
estimates store D

outreg2 [A B C D] using "/Users/peterjohn/Dropbox/documents/experiments/FOI-replication/data/Table 1.doc", label replace word alpha(0.001, 0.01, 0.05)


** margins

oprobit Response Group income Residents FOIpres previousrequests meetingminutes pretreated
margins, dydx(Group) atmeans
marginsplot, yline(0) 

** conditional margins

gen pre=pretreated

oprobit Response c.Group income Residents FOIpres previousrequests meetingminutes c.pre c.pre#c.Group 

margins, dydx(Group) atmeans at (pre=0) at (pre=1)

marginsplot, yline(0) xtitle(Pre-treated) xdimension(at(pre)) nosimplelabels title( "Marginal Effects of FOI Conditional on Pre-treatment" )

reg Response c.Group income Residents FOIpres previousrequests meetingminutes c.pretreated c.pretreated#c.Group 

margins, dydx(Group) atmeans at (pretreated=0) at (pretreated=1)

marginsplot, yline(0) 

probit response01000 c.Group income Residents FOIpres previousrequests meetingminutes c.pretreated c.pretreated#c.Group 

margins, dydx(Group) atmeans at (pretreated=0) at (pretreated=1)

marginsplot, yline(0)

probit response00100 c.Group income Residents FOIpres previousrequests meetingminutes c.pretreated c.pretreated#c.Group 

margins, dydx(Group) atmeans at (pretreated=0) at (pretreated=1)

marginsplot, yline(0)

probit response00100 c.Group income Residents FOIpres previousrequests meetingminutes c.pre c.pre#c.Group 

margins, dydx(Group) atmeans at (pre=0) at (pre=1)

marginsplot, yline(0)xtitle(Pre-treated) xdimension(at(pre)) nosimplelabels title( "Conditional Effect of FOI on 'Send Link or Background'" )



probit response00010 c.Group income Residents FOIpres previousrequests meetingminutes c.pretreated c.pretreated#c.Group 

margins, dydx(Group) atmeans at (pretreated=0) at (pretreated=1)

marginsplot, yline(0)

probit response00001 c.Group income Residents FOIpres previousrequests meetingminutes c.pretreated c.pretreated#c.Group 

margins, dydx(Group) atmeans at (pretreated=0) at (pretreated=1)

marginsplot, yline(0)



oprobit Response income Residents FOIpres previousrequests meetingminutes c.Group c.Residents c.Residents#c.Group 

margins, dydx(Group) atmeans at (Residents=(10000(2000)60000))

marginsplot, yline(0) title( "Marginal Effects of FOI Conditional on Population Size" )


reg Response income Residents FOIpres previousrequests meetingminutes c.Group c.Residents c.Residents#c.Group 

margins, dydx(Group) atmeans at (Residents=(10000(2000)60000))

marginsplot, yline(0) title( "Marginal Effects of FOI Conditional on Population Size: OLS" )


** post-estimation

oprobit Response Group
listcoef, help 


** OLS and probit estimates for appendix

reg Response Group
estimates store i

reg Response Group income Residents FOIpres previousrequests meetingminutes pretreated
estimates store ii

reg Response Group income Residents FOIpres previousrequests meetingminutes pretreated ResidentsGroup
estimates store iii

reg Response Group income Residents FOIpres previousrequests meetingminutes pretreated pretreatedGroup
estimates store iv

outreg2 [i ii iii iv] using "/Users/peterjohn/Dropbox/documents/experiments/FOI-replication/data/Table 1-OLS.doc", label replace word alpha(0.001, 0.01, 0.05)

probit response01000 Group
estimates store a2

probit response01000 Group income Residents FOIpres previousrequests meetingminutes pretreated
estimates store b2

probit response01000 Group income Residents FOIpres previousrequests meetingminutes pretreated ResidentsGroup
estimates store c2

probit response01000 Group income Residents FOIpres previousrequests meetingminutes pretreated pretreatedGroup
estimates store d2

outreg2 [a2 b2 c2 d2] using "/Users/peterjohn/Dropbox/documents/experiments/FOI-replication/data/AppendixTable D2.doc", label replace word alpha(0.001, 0.01, 0.05)


probit response00100 Group
estimates store a3

probit response00100 Group income Residents FOIpres previousrequests meetingminutes pretreated
estimates store b3

probit response00100 Group income Residents FOIpres previousrequests meetingminutes pretreated ResidentsGroup
estimates store c3

probit response00100 Group income Residents FOIpres previousrequests meetingminutes pretreated pretreatedGroup
estimates store d3

outreg2 [a3 b3 c3 d3] using "/Users/peterjohn/Dropbox/documents/experiments/FOI-replication/data/AppendixTable D3.doc", label replace word alpha(0.001, 0.01, 0.05)


probit response00010 Group
estimates store a4

probit response00010 Group income Residents FOIpres previousrequests meetingminutes pretreated
estimates store b4

probit response00010 Group income Residents FOIpres previousrequests meetingminutes pretreated ResidentsGroup
estimates store c4

probit response00010 Group income Residents FOIpres previousrequests meetingminutes pretreated pretreatedGroup
estimates store d4

outreg2 [a4 b4 c4 d4] using "/Users/peterjohn/Dropbox/documents/experiments/FOI-replication/data/AppendixTable D4.doc", label replace word alpha(0.001, 0.01, 0.05)


probit response00001 Group
estimates store a5

probit response00001 Group income Residents FOIpres previousrequests meetingminutes pretreated
estimates store b5

probit response00001 Group income Residents FOIpres previousrequests meetingminutes pretreated ResidentsGroup
estimates store c5

probit response00001 Group income Residents FOIpres previousrequests meetingminutes pretreated pretreatedGroup
estimates store d5

outreg2 [a5 b5 c5 d5] using "/Users/peterjohn/Dropbox/documents/experiments/FOI-replication/data/AppendixTable D5.doc", label replace word alpha(0.001, 0.01, 0.05)







reg Response Group
listcoef, help 

** take out pre-treated

oprobit Response Group if pretreated==1
estimates store i
oprobit Response Group income Residents FOIpres previousrequests meetingminutes if pretreated==1
estimates store ii

** interaction ** 

oprobit Response Group income Residents FOIpres previousrequests meetingminutes ResidentsGroup if pretreated==1
estimates store iii

outreg2 [i ii iii] using "/Users/peterjohn/Dropbox/documents/experiments/FOI-replication/data/Table 1y.doc", label replace word alpha(0.001, 0.01, 0.05)


** response time

reg Responsetime Group
oneway Responsetime Group

clear
